package com.yaosheng.thread.lock;

import java.util.concurrent.Semaphore;

/**
 * Created by yaosheng on 2021/6/30.
 */
public class TestSemaphore {

    public static void main(String[] args) {

        Semaphore s = new Semaphore (2,true);
        //允许多个线程同时执行

        new Thread ( () -> {
            try{
                s.acquire (); //取得值
                System.out.println ("T1 Running");
                Thread.sleep (200);
                System.out.println ("T1 Running");
            }catch (InterruptedException e){
                e.printStackTrace ();
            }finally {
                s.release ();
            }
        }).start ();
    }
}
